<template>
  <div class="app-container">
    <div class="filter-container" >
      <!--<div style="height: 30px;">
        <span>营业汇总表</span>
      </div>-->
      <searchBar @searchEvent= "handleFilter">
        <div slot="one" style="display: inline-block;">
          <el-select v-model="listQuery.around" placeholder="均价金额" clearable style="width: 120px" class="filter-item">
            <el-option v-for="item in importanceOptions" :key="item.key" :label="item.txt" :value="item.key"/>
          </el-select>
        </div>
      </searchBar>
    </div>
    <div style="height: 50px;margin-top: 20px;padding: 0 12px; background:#eee; line-height: 50px;">
      <span>品牌订单报表</span>
      <el-button v-waves style="float: right; margin-top: 7px;" class="filter-item" type="primary" @click="download">月报表</el-button>
    </div>
    <el-table
      v-loading="listLoading"
      :key="tableKey"
      :data="overAll"
      __height="550"
      border
      fit
      highlight-current-row
      style="width: 100%;">
      <el-table-column label="品牌名称" fixed align="center" width="110">
        <template slot-scope="scope">
          <span>{{ scope.row.brandName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单总数" fixed width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.orderDto && scope.row.orderDto.orderCount || 0 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="微信订单总数" fixed width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.orderDto && scope.row.orderDto.wechatOrderCount || 0 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="POS订单总数" fixed width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.orderDto && scope.row.orderDto.posOrderCount || 0 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单总额" fixed width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.orderDto && scope.row.orderDto.orderPrice || 0 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="实收金额" fixed width="110" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.orderDto && scope.row.orderDto.netReceiptsMoney || 0 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="折扣金额" fixed align="center" width="80px">
        <template slot-scope="scope">
          <span>{{ scope.row.orderDto && scope.row.orderDto.reduceMoney || 0 }}</span>
        </template>
      </el-table-column>

      <el-table-column label="就餐人数" align="center" width="80px">
        <template slot-scope="scope">
          <span>{{ scope.row.orderDto && scope.row.orderDto.peopleCount || 0 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="人均" align="center" width="80px">
        <template slot-scope="scope">
          <span>{{ scope.row.orderDto && scope.row.orderDto.perCapita || 0 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="单均" align="center" width="80px">
        <template slot-scope="scope">
          <span>{{ scope.row.orderDto && scope.row.orderDto.orederCapita || 0 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="堂吃" align="center" >
        <el-table-column label="订单数" align="center" width="80px">
          <template slot-scope="scope">
            <span>{{ scope.row.tangshiDto && scope.row.tangshiDto.tangshiCount || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单数占比" align="center" width="110px">
          <template slot-scope="scope">
            <span>{{ scope.row.tangshiDto && scope.row.tangshiDto.tangshiCountProportion || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单额" align="center" width="110">
          <template slot-scope="scope">
            <span>{{ scope.row.tangshiDto && scope.row.tangshiDto.tangshiPrice || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单额占比" align="center" width="110px">
          <template slot-scope="scope">
            <span>{{ scope.row.tangshiDto && scope.row.tangshiDto.tangshiPriceProportion || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="折扣额" align="center" width="80px">
          <template slot-scope="scope">
            <span>{{ scope.row.tangshiDto && scope.row.tangshiDto.tangshieraseMoney || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="折扣额占比" align="center" width="110px">
          <template slot-scope="scope">
            <span>{{ scope.row.tangshiDto && scope.row.tangshiDto.tangshieraseMoneyProportion || 0 }}</span>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="外卖" align="center" >
        <el-table-column label="订单数" align="center" width="80px">
          <template slot-scope="scope">
            <span>{{ scope.row.takeOutDto && scope.row.takeOutDto.takeOutCount || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单数占比" align="center" width="110px">
          <template slot-scope="scope">
            <span>{{ scope.row.takeOutDto && scope.row.takeOutDto.takeOutCountProportion || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单额" align="center" width="80px">
          <template slot-scope="scope">
            <span>{{ scope.row.takeOutDto && scope.row.takeOutDto.takeOutPrice || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单额占比" align="center" width="110px">
          <template slot-scope="scope">
            <span>{{ scope.row.takeOutDto && scope.row.takeOutDto.takeOutPriceProportion || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="折扣额" align="center" width="80px">
          <template slot-scope="scope">
            <span>{{ scope.row.takeOutDto && scope.row.takeOutDto.takeOutEraseMoney || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="折扣额占比" align="center" width="110px">
          <template slot-scope="scope">
            <span>{{ scope.row.takeOutDto && scope.row.takeOutDto.takeOutMoneyProportion || 0 }}</span>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="R+外卖" align="center" >
        <el-table-column label="订单数" align="center" width="80px">
          <template slot-scope="scope">
            <span>{{ scope.row.rtakeOutiDto && scope.row.rtakeOutiDto.rtakeOutCount || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单数占比" align="center" width="110px">
          <template slot-scope="scope">
            <span>{{ scope.row.rtakeOutiDto && scope.row.rtakeOutiDto.rtakeOutCountProportion || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单额" align="center" width="80px">
          <template slot-scope="scope">
            <span>{{ scope.row.rtakeOutiDto && scope.row.rtakeOutiDto.rtakeOutPrice || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单额占比" align="center" width="110px">
          <template slot-scope="scope">
            <span>{{ scope.row.rtakeOutiDto && scope.row.rtakeOutiDto.rtakeOutPriceProportion || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="折扣额" align="center" width="100px">
          <template slot-scope="scope">
            <span>{{ scope.row.rtakeOutiDto && scope.row.rtakeOutiDto.rtakeOutEraseMoney || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="折扣额占比" align="center" width="110px">
          <template slot-scope="scope">
            <span>{{ scope.row.rtakeOutiDto && scope.row.rtakeOutiDto.rtakeOutMoneyProportion || 0 }}</span>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="外带" align="center" >
        <el-table-column label="订单数" align="center" width="80px">
          <template slot-scope="scope">
            <span>{{ scope.row.takeAwayDto && scope.row.takeAwayDto.takeAwayCount || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单数占比" align="center" width="110px">
          <template slot-scope="scope">
            <span>{{ scope.row.takeAwayDto && scope.row.takeAwayDto.takeAwayCountProportion || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单额" align="center" width="80px">
          <template slot-scope="scope">
            <span>{{ scope.row.takeAwayDto && scope.row.takeAwayDto.takeAwayiPrice || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单额占比" align="center" width="110px">
          <template slot-scope="scope">
            <span>{{ scope.row.takeAwayDto && scope.row.takeAwayDto.takeAwayiPriceProportion || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="折扣额" align="center" width="100px">
          <template slot-scope="scope">
            <span>{{ scope.row.takeAwayDto && scope.row.takeAwayDto.takeAwayEraseMoney || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="折扣额占比" align="center" width="110px">
          <template slot-scope="scope">
            <span>{{ scope.row.takeAwayDto && scope.row.takeAwayDto.takeAwayMoneyProportion || 0 }}</span>
          </template>
        </el-table-column>
      </el-table-column>
    </el-table>
    <!--<pagination v-show="total>0" :total="total" layout="total, sizes, prev, pager, next, jumper" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />-->

    <div style="height: 50px;margin-top: 20px;padding: 0 12px; background:#eee; line-height: 50px;">
      <span>店铺订单报表</span>
      <el-button v-waves style="float: right; margin-top: 7px;" class="filter-item" type="primary" @click="download">月报表</el-button>
    </div>
    <el-table
      v-loading="listLoading"
      :key="1"
      :data="list.slice((pageIndex-1)*pageSize,pageIndex*pageSize)"
      __height="550"
      border
      fit
      highlight-current-row
      style="width: 100%;">
      <el-table-column label="店铺名称" fixed align="center" width="110">
        <template slot-scope="scope">
          <span>{{ scope.row.shopDetailName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单总数" fixed width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.orderDto && scope.row.orderDto.orderCount || 0 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="微信订单总数" fixed width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.orderDto && scope.row.orderDto.wechatOrderCount || 0 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="POS订单总数" fixed width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.orderDto && scope.row.orderDto.posOrderCount || 0 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单总额" fixed width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.orderDto && scope.row.orderDto.orderPrice || 0 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="实收金额" fixed width="80px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.orderDto && scope.row.orderDto.netReceiptsMoney || 0 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="折扣金额" fixed align="center" width="80px">
        <template slot-scope="scope">
          <span>{{ scope.row.orderDto && scope.row.orderDto.reduceMoney || 0 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="就餐人数" align="center" width="80px">
        <template slot-scope="scope">
          <span>{{ scope.row.orderDto && scope.row.orderDto.peopleCount || 0 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="人均" align="center" width="80px">
        <template slot-scope="scope">
          <span>{{ scope.row.orderDto && scope.row.orderDto.perCapita || 0 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="单均" align="center" width="80px">
        <template slot-scope="scope">
          <span>{{ scope.row.orderDto && scope.row.orderDto.orederCapita || 0 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="堂吃" align="center" >
        <el-table-column label="订单数" align="center" width="80px">
          <template slot-scope="scope">
            <span>{{ scope.row.tangshiDto && scope.row.tangshiDto.tangshiCount || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单数占比" align="center" width="110px">
          <template slot-scope="scope">
            <span>{{ scope.row.tangshiDto && scope.row.tangshiDto.tangshiCountProportion || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单额" align="center" width="80px">
          <template slot-scope="scope">
            <span>{{ scope.row.tangshiDto && scope.row.tangshiDto.tangshiPrice || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单额占比" align="center" width="110px">
          <template slot-scope="scope">
            <span>{{ scope.row.tangshiDto && scope.row.tangshiDto.tangshiPriceProportion || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="折扣额" align="center" width="80px">
          <template slot-scope="scope">
            <span>{{ scope.row.tangshiDto && scope.row.tangshiDto.tangshieraseMoney || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="折扣额占比" align="center" width="110px">
          <template slot-scope="scope">
            <span>{{ scope.row.tangshiDto && scope.row.tangshiDto.tangshieraseMoneyProportion || 0 }}</span>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="外卖" align="center" >
        <el-table-column label="订单数" align="center" width="80px">
          <template slot-scope="scope">
            <span>{{ scope.row.takeOutDto && scope.row.takeOutDto.takeOutCount || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单是占比" align="center" width="110px">
          <template slot-scope="scope">
            <span>{{ scope.row.takeOutDto && scope.row.takeOutDto.takeOutCountProportion || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单额" align="center" width="80px">
          <template slot-scope="scope">
            <span>{{ scope.row.takeOutDto && scope.row.takeOutDto.takeOutPrice || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单额占比" align="center" width="110px">
          <template slot-scope="scope">
            <span>{{ scope.row.takeOutDto && scope.row.takeOutDto.takeOutPriceProportion || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="折扣额" align="center" width="80px">
          <template slot-scope="scope">
            <span>{{ scope.row.takeOutDto && scope.row.takeOutDto.takeOutEraseMoney || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="折扣额占比" align="center" width="110px">
          <template slot-scope="scope">
            <span>{{ scope.row.takeOutDto && scope.row.takeOutDto.takeOutMoneyProportion || 0 }}</span>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="R+外卖" align="center" >
        <el-table-column label="订单数" align="center" width="80px">
          <template slot-scope="scope">
            <span>{{ scope.row.rtakeOutiDto && scope.row.rtakeOutiDto.rtakeOutCount || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单数占比" align="center" width="110px">
          <template slot-scope="scope">
            <span>{{ scope.row.rtakeOutiDto && scope.row.rtakeOutiDto.rtakeOutCountProportion || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单额" align="center" width="80px">
          <template slot-scope="scope">
            <span>{{ scope.row.rtakeOutiDto && scope.row.rtakeOutiDto.rtakeOutPrice || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单额占比" align="center" width="110px">
          <template slot-scope="scope">
            <span>{{ scope.row.rtakeOutiDto && scope.row.rtakeOutiDto.rtakeOutPriceProportion || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="折扣额" align="center" width="80px">
          <template slot-scope="scope">
            <span>{{ scope.row.rtakeOutiDto && scope.row.rtakeOutiDto.rtakeOutEraseMoney || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="折扣额占比" align="center" width="110px">
          <template slot-scope="scope">
            <span>{{ scope.row.rtakeOutiDto && scope.row.rtakeOutiDto.rtakeOutMoneyProportion || 0 }}</span>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="外带" align="center" >
        <el-table-column label="订单数" align="center" width="80px">
          <template slot-scope="scope">
            <span>{{ scope.row.takeAwayDto && scope.row.takeAwayDto.takeAwayCount || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单数占比" align="center" width="110px">
          <template slot-scope="scope">
            <span>{{ scope.row.takeAwayDto && scope.row.takeAwayDto.takeAwayCountProportion || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单额" align="center" width="80px">
          <template slot-scope="scope">
            <span>{{ scope.row.takeAwayDto && scope.row.takeAwayDto.takeAwayiPrice || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单额占比" align="center" width="110px">
          <template slot-scope="scope">
            <span>{{ scope.row.takeAwayDto && scope.row.takeAwayDto.takeAwayiPriceProportion || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="折扣额" align="center" width="80px">
          <template slot-scope="scope">
            <span>{{ scope.row.takeAwayDto && scope.row.takeAwayDto.takeAwayEraseMoney || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="折扣额占比" align="center" width="110px">
          <template slot-scope="scope">
            <span>{{ scope.row.takeAwayDto && scope.row.takeAwayDto.takeAwayMoneyProportion || 0 }}</span>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="操作" fixed="right" align="center" width="80px">
        <template slot-scope="scope">
          <Link @gotoDetail="gotoDetail(scope.row)">查看详情</Link>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      :current-page="pageIndex"
      :page-sizes="[5, 10]"
      :total="20"
      style="margin-top: 20px;"
      layout="total, sizes, prev, pager, next, jumper"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"/>

  </div>
</template>

<script>
import waves from '@/directive/waves' // Waves directive
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import { parseTime } from '@/utils'

import searchBar from '@/pages/common/searchBar'
import Link from '@/pages/common/Link'
import ReportSearchMixin from '@/pages/common/mixin/ReportSearch.js'

export default {
  name: 'ComplexTable',
  components: { searchBar, Pagination, Link },
  directives: { waves },
  mixins: [ReportSearchMixin],
  data() {
    return {
      listQuery: {
        beginDate: parseTime(new Date().getTime(), '{y}-{m}-{d} 00:00:00'),
        endDate: parseTime(new Date().getTime(), '{y}-{m}-{d} {h}:{i}:{s}'),
        around: 1 // 默认按折前
      },
      importanceOptions: [
        { key: 1, txt: '按折前' },
        { key: 2, txt: '按折后' }
      ],
      overAllUrl: '/service-report/data/BrandList', // 概览接口地址
      listUrl: '/service-report/data/ShopList' // 列表接口地址
    }
  },
  async created() {
    await this.fetchData()
  },
  methods: {

    // 跳转到店铺订单列表
    gotoDetail(row) {
      this.$router.push({ path: '/order-report/stats/dingdan/orderlist', query: { shopDetailId: row.shopDetailId, shopDetailName: row.shopDetailName }})
    }
  }
}
</script>
